package com.burgeon.backend.SHOPBACKEND.controller;
/**
 * 预售
 */

import com.burgeon.backend.SHOPBACKEND.entity.presell.PresellConfig;
import com.burgeon.backend.SHOPBACKEND.service.BackendPresellService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RequestMapping("backend/presell")
@RestController
@CrossOrigin
public class BackendPresellController extends BaseController {

    @Autowired
    private BackendPresellService backendPresellService;

    @RequestMapping("getimg")
    public ResponseResult<String> getGroupImg(String account) {
        String data = backendPresellService.getImg(account);

        return new ResponseResult<String>(SUCCESS,data);
    }

    @RequestMapping("upimg")
    public ResponseResult<String> groupImg(@RequestParam(value = "img") MultipartFile img, String account) {
        String data = backendPresellService.upImg(img, account);

        return new ResponseResult<String>(SUCCESS,data);
    }


    @RequestMapping("agreementData")
    public ResponseResult<String> agreementData(String account) {

        String data = backendPresellService.getAgreement(account);

        return new ResponseResult<String>(SUCCESS,data);
    }

    @RequestMapping("upAgreement")
    public ResponseResult<Void> upAgreement(String body,String account) {

        backendPresellService.upAgreement(body,account);

        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("del")
    public ResponseResult<Void> delPresell(String id) {

        backendPresellService.delPresell(id);

        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("create")
    public ResponseResult<Void> addPresell(PresellConfig presellConfig) {

        backendPresellService.createPresell(presellConfig);

        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("data")
    public ResponseResult<List<PresellConfig>> getData(String account) {

        List<PresellConfig> data = backendPresellService.getData(account);

        return new ResponseResult<List<PresellConfig>>(SUCCESS, data);
    }


}
